<?php
/**
 * Created by swagger_zxd.
 * User: zxd
 * Date: 2018/2/27
 * Time: 11:36
 */

namespace app\player\model;


use think\Model;

class Player extends Model{

    /**
     * 玩家搜索列表
     * @param $page
     * @param $pageSize
     * @param $uType
     * @param $userid
     * @param $begin
     * @param $end
     * @param $beginLog
     * @param $endLog
     * @param $minScore
     * @param $maxScore
     * @param $minPrize
     * @param $maxPrize
     * @param $minZsy
     * @param $maxZsy
     * @param $minDrsy
     * @param $maxDrsy
     * @param $minZengSongCha
     * @param $maxZengSongCha
     * @param $phone
     * @param $loginIp
     * @param $regIp
     * @param $userState
     * @param $userType
     * @param $platform
     * @param $state
     * @param $zbType
     * @param $gamePlatform
     * @param $order
     * @return \think\response\Json
     */
    public function searchPlayerListData($page,$pageSize,$uType,$userid,$begin,$end,$beginLog, $endLog,$minScore,$maxScore,$minPrize,$maxPrize,$minZsy, $maxZsy,$minDrsy,$maxDrsy,$minZengSongCha,$maxZengSongCha, $phone,$loginIp,$regIp,$userState,$userType,$platform,$state, $zbType,$gamePlatform,$order){
        $records="";
        try{
            $pdo=odbcLink();
            $sqlstr="exec bg_SelectUser4 "
                .$uType.", ".$userid.",".$begin.", ".$end.", "
                .$beginLog.", ".$endLog.",".$minScore.", ".$maxScore.", "
//			.$minCzScore.", ".$maxCzScore.", "
                .$minPrize.", ".$maxPrize.", ".$minZsy.", "
                .$maxZsy.", ".$minDrsy.", ".$maxDrsy.", ".$minZengSongCha.", ".$maxZengSongCha.", "
                .$phone.", ".$loginIp.", ".$regIp.", ".$userState.", ".$userType.", ".$platform.", ".$order.", "
//			.$state.", ".$zbType.", ".$gamePlatform.", ".$order.", "
                .$page;

            $sql = iconv("utf-8", "gbk", $sqlstr);//sql转码

            $sth=$pdo->query($sql);
            $i=1;
            do{
                $rowset=$sth->fetchAll(\PDO::FETCH_ASSOC);
                switch($i){
                    case 1:
                        $count=$rowset[0]['c'];
                        $pageinfo=['count'=>$count,'page'=>$page];
                        break;
                    case 2:
                        if(!empty($rowset)){
                            foreach ($rowset as $k=>$value) {
                                $zx="大厅";
//                                $records[$k]['zx']=$rowset[$k]['zx']?iconv("gbk","utf-8",$rowset[$k]['zx']):$zx;
                                $records[$k]['gameId']=$rowset[$k]['GameID'];
//                                $records[$k]['nickName']=iconv("gbk","utf-8",$rowset[$k]['NickName']);
                                $records[$k]['score']=$rowset[$k]['score'];
                                $records[$k]['prizes']=$rowset[$k]['prizes'];
                                $records[$k]['cz']=$rowset[$k]['cz'];
                                $records[$k]['ZengSongCha']=$rowset[$k]['sendnum'];
                                $records[$k]['regTime']=$rowset[$k]['RegisterDate'];
                                $records[$k]['lastLoginTime']=$rowset[$k]['LastLoginTime'];
                                $records[$k]['TodayScore']=$rowset[$k]['TodayScore'];
                                $records[$k]['realScore']=$rowset[$k]['RealScore'];
                                $records[$k]['czcs']=$rowset[$k]['czcs'];
                                $records[$k]['cheatRate']=$rowset[$k]['CheatRate'];
                                $records[$k]['limitScore']=$rowset[$k]['LimitScore'];
                                $records[$k]['bloodScore']=$rowset[$k]['BloodScore'];
                                $records[$k]['platform']=$rowset[$k]['Platform_Id'];
//                                $records[$k]['packName']=iconv("gbk","utf-8",$rowset[$k]['PackName']);
                                $records[$k]['userKind']=$rowset[$k]['userKind'];
                            }
                        }
                        break;
                }
                $i++;
            }while($sth->nextRowset());
        }catch(\Exception $e){
            echo $e->getMessage();
        }
        $out=['pageInfo'=>$pageinfo,'records'=>$records,"sql"=>$sqlstr];
        return json($out);
    }

    /**
     * 锁定或解除锁定
     * @param $gameIdStr
     * @param $type
     * @param $memo
     * @return int
     */
    public function batchLockOrUnlockUser($gameIdStr,$type,$memo){
        try{
            $pdo=odbcLink();
            $ip=getIPaddress();
            $sqlstr="exec JJ_LockUserByList ".$type.", 55, '".$memo."', '".$ip."', '".$gameIdStr."', ''";
            $sql=iconv("utf-8","gbk",$sqlstr);

            $pdo->exec($sql);
            //todo 后期解决transferDLL com报错
            //transferDLL(14, 0, 0, 0, 'update');
            return 1;
        }catch(\Exception $e){
            echo $e->getMessage();
        }
    }

    /**
     * 是否锁定
     * @param $gameId
     * @return \think\response\Json
     */
    public function isLock($gameId){
        $pdo=odbcLink();
        $sqlstr="select LimitLogin from AccountsInfo where GameID = ".$gameId;
        $sql=iconv("utf-8","gbk",$sqlstr);
        $sth=$pdo->query($sql);
        $i=1;
        try{
            do{
                $rowset=$sth->fetchAll(\PDO::FETCH_ASSOC);
                switch($i){
                    case 1:
                        $islock=$rowset[0]['LimitLogin'];
                        break;
                }
                $i++;
            }while($sth->nextRowset());
        }catch(\Exception $e){
            echo $e->getMessage();
        }
         return json($islock);
    }
}